<template>
  <div :class="{ 'dark-mode': isDarkMode }" class="panel">
    <!-- 标题区域 -->
    <div class="header-section">
      <h1 class="title">{{ discipline.name }}</h1>
      <el-tag
        v-if="discipline.super_disciplines && discipline.super_disciplines.length"
        :effect="isDarkMode ? 'dark' : 'light'"
        class="category-tag"
        size="small"
      >
        {{ discipline.super_disciplines.join("/") }}
      </el-tag>
    </div>

    <!-- 描述部分 -->
    <div class="content-section">
      <h3 class="section-title">
        <el-icon>
          <Document />
        </el-icon>
        {{ discriptionLabel }}
      </h3>
      <div class="section-content">
        <el-text>{{ discipline.description }}</el-text>
      </div>
    </div>

    <!-- 历史部分 -->
    <div class="content-section">
      <h3 class="section-title">
        <el-icon>
          <Timer />
        </el-icon>
        {{ historyLabel }}
      </h3>
      <div class="section-content">
        <el-text>{{ discipline.history }}</el-text>
      </div>
    </div>

    <!-- 作品部分 -->
    <div class="content-section">
      <h3 class="section-title">
        <el-icon>
          <Collection />
        </el-icon>
        {{ workLabel }}
      </h3>
      <div class="works-container">
        <div v-for="work in discipline.famous_works" :key="work.name" class="work-item">
          <div class="work-header">
            <span class="work-title">{{ work.name }}</span>
            <el-tag :type="isDarkMode ? '' : 'info'" size="small">{{ work.author }}</el-tag>
          </div>
          <div class="work-description">
            {{ work.description }}
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<style scoped>
.panel {
  position: absolute;
  display: flex;
  flex-direction: column;
  max-height: 90vh;
  overflow-y: auto;
  background-color: rgba(255, 255, 255, 0.95);
  width: 360px;
  bottom: 2%;
  right: 2%;
  padding: 16px;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  font-size: 14px;
  transition: all 0.3s ease;
}

.header-section {
  margin-bottom: 16px;
  border-bottom: 1px solid #eaeaea;
  padding-bottom: 12px;
}

.title {
  font-size: 20px;
  font-weight: 600;
  color: #303133;
  margin: 0 0 8px 0;
  line-height: 1.2;
}

.category-tag {
  font-size: 12px;
}

.content-section {
  margin-bottom: 16px;
}

.content-section:last-child {
  margin-bottom: 0;
}

.section-title {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 15px;
  font-weight: 500;
  color: #409eff;
  margin: 0 0 8px 0;
  line-height: 1;
}

.section-title .el-icon {
  font-size: 14px;
}

.section-content {
  color: #606266;
  line-height: 1.5;
  text-align: justify;
  font-size: 13px;
}

.works-container {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.work-item {
  background-color: #f5f7fa;
  border-radius: 4px;
  padding: 8px 12px;
  transition: background-color 0.2s;
}

.work-item:hover {
  background-color: #ecf5ff;
}

.work-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.work-title {
  font-weight: 500;
  color: #303133;
  font-size: 13px;
}

.work-description {
  color: #606266;
  font-size: 12px;
  line-height: 1.4;
}

/* 深色模式样式 */
.dark-mode {
  background-color: rgba(30, 30, 30, 0.95);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
}

.dark-mode .header-section {
  border-bottom-color: #363637;
}

.dark-mode .title {
  color: #e5eaf3;
}

.dark-mode .section-title {
  color: #79bbff;
}

.dark-mode .section-content {
  color: #cfd3dc;
}

.dark-mode .work-item {
  background-color: rgba(0, 0, 0, 0.15);
}

.dark-mode .work-item:hover {
  background-color: rgba(64, 158, 255, 0.1);
}

.dark-mode .work-title {
  color: #e5eaf3;
}

.dark-mode .work-description {
  color: #cfd3dc;
}

/* 滚动条样式 */
.panel::-webkit-scrollbar {
  width: 4px;
}

.panel::-webkit-scrollbar-track {
  background: transparent;
}

.panel::-webkit-scrollbar-thumb {
  background: #dcdfe6;
  border-radius: 2px;
}

.panel::-webkit-scrollbar-thumb:hover {
  background: #c0c4cc;
}

.dark-mode::-webkit-scrollbar-thumb {
  background: #4c4d4f;
}

.dark-mode::-webkit-scrollbar-thumb:hover {
  background: #6b6c6e;
}

/* 确保内容不会被滚动条遮挡 */
.panel {
  scrollbar-gutter: stable;
}
</style>

<script lang="ts">
export default {
  name: 'DetailPanel'
}
</script>

<script lang="ts" setup>
import { useThemeStore } from '@/stores/theme'
import { storeToRefs } from 'pinia'
import { Document, Timer, Collection } from '@element-plus/icons-vue'
import type { Discipline } from '@/utils/models'
import * as labels from '@/utils/labels'

const themeStore = useThemeStore()
const { isDarkMode } = storeToRefs(themeStore)
// 定义 props
const props = defineProps<{
  discipline: Discipline
}>()

const discriptionLabel = labels.dp_dspl_disc
const historyLabel = labels.dp_dspl_hist
const workLabel = labels.dp_dspl_work
</script>
